package it.learn.kafka.init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class Test02 implements CommandLineRunner {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Override
    public void run(String... args) throws Exception {

        List<String> serviceNames = discoveryClient.getServices();
        System.out.println("serviceNames.size() = " + serviceNames.size());

        System.out.println("===============================");

        List<ServiceInstance> instances = discoveryClient.getInstances("gateway8090");
        String baseUrl = instances.get(0).getUri().toString();
        System.out.println("baseUrl = " + baseUrl);

    }

}
